﻿Imports Microsoft.VisualBasic
Imports Comunes
Imports System.Data
Imports System.Xml

Public Class cls_pwdApp
    Dim v_obj_wsService As New Service.Service
    Dim v_obj_clsParametros As New Parametros()
    Dim v_obj_clsLibreria As New clsLibreria()
    Dim v_dts_respuesta As New DataSet
    Dim v_obj_json As New clsJsonSR.clsJsonSR()
    Dim v_obj_clsErrores As New cls_errores()
    Dim v_str_keyConn As String = System.Configuration.ConfigurationManager.AppSettings.Get("KeyConexion")
    Dim v_str_glsError As String = ""
    Dim v_str_srcError As String = ""
    Dim v_str_wsError As String = ""
    Dim v_str_metError As String = ""
    Dim v_str_numError As String = ""

    Private _p_str_old_password As String
    Private _p_str_new_password As String
    Private _USUS_NID As String

    Sub New()
        _p_str_old_password = ""
        _p_str_new_password = ""
        _USUS_NID = ""
    End Sub

    Public Property p_str_old_password() As String
        Get
            Return _p_str_old_password
        End Get
        Set(ByVal value As String)
            _p_str_old_password = value
        End Set
    End Property

    Public Property p_str_new_password() As String
        Get
            Return _p_str_new_password
        End Get
        Set(ByVal value As String)
            _p_str_new_password = value
        End Set
    End Property
    Public Property USUS_NID() As String
        Get
            Return _USUS_NID
        End Get
        Set(ByVal value As String)
            _USUS_NID = value
        End Set
    End Property

    Public Function grabarNuevaClave() As String
        Dim v_str_respuestaJson As String = ""
        Try
            v_obj_clsErrores.id = 0
            v_obj_clsErrores.desc = ""
            v_obj_clsErrores.clase = "cls_pwdApp"
            v_obj_clsErrores.metodo = "grabarNuevaClave"
            v_obj_clsParametros.Limpiar()
            v_obj_clsParametros.Agregar("p_str_old_password", Me._p_str_old_password)
            v_obj_clsParametros.Agregar("p_str_new_password", Me._p_str_new_password)
            v_obj_clsParametros.Agregar("p_str_nid_user", Me.USUS_NID)
            v_dts_respuesta = v_obj_wsService.EjecutarConParametroXML(v_str_keyConn, v_obj_clsParametros.GeneraDocXML("parametros"), "SPBS_USUS_ACTUALIZA_CLAVE")
            If v_obj_clsLibreria.RevisaErrores(v_dts_respuesta, v_str_glsError, v_str_srcError, v_str_wsError, v_str_metError, v_str_numError) = "0" Then
                v_str_respuestaJson = v_obj_json.respuestaFormularioJson(True, v_dts_respuesta.Tables(0), v_obj_clsErrores)
            Else
                v_obj_clsErrores.id = v_str_numError
                v_obj_clsErrores.desc = v_str_glsError
                v_obj_clsErrores.registraErrorEnLog()
                v_str_respuestaJson = v_obj_json.respuestaFormularioJson(False, v_dts_respuesta.Tables(0), Nothing)
            End If
        Catch ex As Exception
            v_obj_clsErrores.id = -1000
            v_obj_clsErrores.desc = ex.Message
            v_obj_clsErrores.registraErrorEnLog()
            v_str_respuestaJson = v_obj_json.respuestaFormularioJson(False, v_dts_respuesta.Tables(0), v_obj_clsErrores)
        Finally
            v_dts_respuesta = Nothing
            v_obj_clsParametros.Dispose()
            v_obj_clsParametros = Nothing
            v_obj_wsService.Dispose()
            v_obj_wsService = Nothing
            v_obj_clsLibreria.Dispose()
            v_obj_clsLibreria = Nothing
        End Try
        Return v_str_respuestaJson
    End Function

End Class
